package com.atguigu.spring.config;

import com.atguigu.spring.bean.Cat;
import com.atguigu.spring.bean.Person;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.*;
import org.springframework.core.type.AnnotationMetadata;

//这是一个配置
//@Import({MyImportRegister.class})
@Configuration
@ComponentScan("com.atguigu.spring")
public class MyConfig {
	/*@Bean
	public Person person(){
		Person person = new Person();
		person.setName("liyanhao");
		return person;
	}*/
}

/**
 *BeanDefinitionRegistry ：Beand定义信息注册中心：图纸中心
 */
class MyImportRegister implements ImportBeanDefinitionRegistrar{
	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
										BeanDefinitionRegistry registry,
										BeanNameGenerator importBeanNameGenerator) {
		//BeanDefinition
		RootBeanDefinition catDefinition = new RootBeanDefinition();
		catDefinition.setBeanClass(Cat.class);
		//可以声明定义信息 包括需要自动装配什么
		//bean的名字
		registry.registerBeanDefinition("tomcat",catDefinition);
	}

	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
										BeanDefinitionRegistry registry) {
		ImportBeanDefinitionRegistrar.super.registerBeanDefinitions(importingClassMetadata, registry);
	}
}
